#include <cstdio>
#include <vector>
#include <functional>
#include <algorithm>

template <
	class T,
	class COMPARE = std::less<T>
>
struct sparse_table
{
	typedef T value_type;
	typedef unsigned int size_type;
	typedef COMPARE comparer;
	typedef std::vector<value_type> vector_type;

	inline size_type log2(size_type len) const
	{
		size_type tmp = 0;
		for (; size_type(1 << tmp) <= len; tmp++); // FIXME 11 neednot write size_type
		return tmp - 1;
	}

	sparse_table(comparer cmp = comparer()) : cmp(cmp) {}

	void init(vector_type const & data)
	{
		size_type n = data.size();
		size_type len = log2(n);

		for (size_type i = 0; i < n; i++) st[i][0] = i;
		for (size_type l = 1; l <= len; l++)
			for (size_type i = 0; (i + (1<<l) - 1) < n; i++)
				if (cmp(data[ st[i][l - 1] ], data[ st[i + (1<<(l-1))][l - 1] ]))
					st[i][l] = st[i][l - 1];
				else
					st[i][l] = st[i + (1 << (l-1))][l - 1];
	}

	// [l, r]
	size_type query_interval_index(vector_type const & data, size_type l, size_type r) const
	{
		int k = log2(r - l + 1);
		if (cmp(data[ st[l][k] ], data[ st[r - (1<<k) + 1][k] ]))
			return st[l][k];
		else
			return st[r - (1<<k) + 1][k];
	}

	// [l, r]
	value_type query_interval(vector_type const & data, size_type l, size_type r) const
	{
		return data[ query_interval_index(data, l, r) ];
	}

private:
	size_type static const maxn = 100007;
	size_type static const  len = 17;
	size_type st[maxn][len];
	comparer cmp;
};


int const inf = 1 << 27;
int n;
sparse_table<int> st;
std::vector<int> num;

int calc(int l, int r) // [l, r]
{
	int t = st.query_interval_index(num, l, r);
	int tmp = inf;
	if (l <= t - 1) tmp = calc(l, t - 1);
	if (t + 1 <= r) tmp = std::min(tmp, calc(t + 1, r));
	if (tmp == inf) tmp = 0;
	return  tmp + 1;
}

int main()
{
	std::scanf("%d", &n);
	num.resize(n);
	for (int i = 0; i < n; i++)
		std::scanf("%d", &num[i]);

	st.init(num);
	std::printf("%d", calc(0, n-1));
}


